package org.telluriumsource.ui.widget.dojo.object;

import demo.tellurium.framework.BaseDojoWidget 

import org.json.simple.JSONObject;

/**
 * Tellurium Widget object for the Dojo CheckBox widget
 *
 * @author Roger Xu (roger.xu.2007@gmail.com)
 *
 * Date: Apr 21, 2010
 * 
 */
class TextBox extends BaseDojoWidget {

    private static final String WIDGET_NAME = TextBox.class.getSimpleName();

    private Map attributes = [:];

    @Override
    public String getWidgetName() {
        return WIDGET_NAME;
    }

    @Override
    public JSONObject toJSON() {
        return buildJSON() {jso ->
            jso.put(UI_TYPE, NAMESPACE + "_" + getWidgetName());
        }
    }

    @Override
    public void defineWidget() {
        def clocator = [tag: "div", class: "dijitTextBox"];
        clocator.putAll(this.attributes);

        ui.Container(uid: "${WIDGET_NAME}", clocator: clocator) {
            Container(uid: "InputField", clocator: [tag: "div", class: "dijitInputField"]) {
                InputBox(uid: "InputTextBox", clocator: [tag: "input", type: "text"])
            }
        }
    }

    public void inputText(String input) {
        def textbox = "${WIDGET_NAME}.InputField.InputTextBox";

        type textbox, input
    }

    public String getValue() {
        def textbox = "${WIDGET_NAME}.InputField.InputTextBox";
        return getValue(textbox);
    }
}